<?php

class auction_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function gets($config)
    {
        
        $id=$config["id"];
        $groupby=$config['group'];
        //$q=$config['q'];
        $sort=$config['sort'];
        if($config['group']=="none")$groupby="''";
        $query = $this->db->query("
            SELECT * ,$groupby as `group`,(select count(*) from `auction` as r2 where r1.`cash`=r2.`cash`) as sl
            FROM `auction` as r1 
            WHERE `delete` is null 
                AND `product`='$id'
            ORDER BY  `cash` ASC
        ");
        return $query->result();
    }
    function gets_auction_detail($userid,$p)
    {
        $str=($p*7);
        $query = $this->db->query("
            SELECT k.*
            FROM (SELECT @row := @row + 1 AS row,a.*,p.`name` as productname
                        FROM `auction`  a,`product` p, (SELECT @row := 0) r
                        WHERE a.`delete` is null 
                            and a.`userid`='$userid'
                            and a.`product`=p.`id`
                        ORDER BY a.`insert` DESC
            ) k
            LIMIT $str,7
        ");
        return $query->result();
    }
    function gets_auction()
    {
        $query = $this->db->query("
            SELECT *
            FROM `product` 
            WHERE `delete` is null 
                AND `status`='Public'
                AND now()BETWEEN `startdate` AND `enddate`
                AND `type`='VVCV01'
        ");
        return $query->result();
    }
    function insert($params){
        $this->db->set('insert', 'NOW()', FALSE);
        $this->db->insert('auction', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    
}
?>
